package com.jasperframework.boot.common.utils;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

/**
  * <p>  </p>
  *
  * @site https://miliqkdoc.motopa.cn/
  * @author daizhao
  * @date 2022/12/12 12:12
  */
public class WebUtils {
	/**
	 * @Description: ie,chrom,firfox下处理文件名显示乱码
	 */
	public  static String processFileName(HttpServletRequest request, String fileNames) {
		String codedfilename = null;
		try {
			String agent = request.getHeader("USER-AGENT");
			if (null != agent && -1 != agent.indexOf("MSIE") || null != agent && -1 != agent.indexOf("Trident")) {// ie
				String name = java.net.URLEncoder.encode(fileNames, "UTF8");
				codedfilename = name;
			} else if (null != agent && -1 != agent.indexOf("Mozilla")) {// 火狐,chrome等
				codedfilename = new String(fileNames.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return codedfilename;
	}
}
